package com.fang.dubbo.mock.spi.config;

import com.alibaba.dubbo.config.ConsumerConfig;
import com.alibaba.dubbo.config.ProviderConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author fanglingxiao
 * @version 1.0
 * @description dubbo config
 * @date 2022/1/4 8:26 下午
 **/
@Configuration
public class DubboConfig {

    @Value("${my.dubbo.consumer.timeout:5000}")
    private Integer consumerTimeout;
    @Value("${my.dubbo.provider.timeout:5000}")
    private Integer providerTimeout;

    @Bean
    public ProviderConfig providerConfig() {
        ProviderConfig providerConfig = new ProviderConfig();
        providerConfig.setFilter("ProviderFilter");
        providerConfig.setTimeout(this.providerTimeout);
        return providerConfig;
    }

    @Bean
    public ConsumerConfig consumerConfig() {
        ConsumerConfig consumerConfig = new ConsumerConfig();
        consumerConfig.setFilter("ConsumerFilter");
        consumerConfig.setLoadbalance("fangLoadBalance");
        consumerConfig.setTimeout(this.consumerTimeout);
        consumerConfig.setCheck(Boolean.FALSE);
        //retries 默认不重试
        consumerConfig.setRetries(-1);
        return consumerConfig;
    }
}
